package deposit.tests;

import java.util.Calendar;
import java.util.GregorianCalendar;
import org.junit.Assert;
import org.junit.Test;
import deposit.main.SimpleDeposit;

public class SimpleDepositTest {

    @Test
    public void getInterestTest1() {
	SimpleDeposit sd = new SimpleDeposit();
	sd.setStartDate(new GregorianCalendar(2012, Calendar.SEPTEMBER, 8)
		.getTime());
	sd.setDayLong(80);
	sd.setSum(1000.0);
	sd.setInterestRate(15.0);

	double expectedInterest = 32.88;
	double actualInterest = sd.getInterest();
	//actualInterest = Math.round(actualInterest * 100.0) / 100.0;
	Assert.assertEquals(expectedInterest, actualInterest, 0.005);
    }

    @Test
    public void getInterestTest2() {
	SimpleDeposit sd = new SimpleDeposit();
	sd.setStartDate(new GregorianCalendar(2012, Calendar.SEPTEMBER, 8)
		.getTime());
	sd.setDayLong(20);
	sd.setSum(1000.00);
	sd.setInterestRate(15.0);
	double expectedInterest = 8.22;
	double actualInterest = sd.getInterest();
	Assert.assertEquals(expectedInterest, actualInterest, 0.005);
    }

    @Test
    public void getInterestTest3() {
	SimpleDeposit sd = new SimpleDeposit();
	sd.setStartDate(new GregorianCalendar(2012, Calendar.SEPTEMBER, 8)
		.getTime());
	sd.setDayLong(30);
	sd.setSum(1000.00);
	sd.setInterestRate(15.0);
	double expectedInterest = 12.33;
	double actualInterest = sd.getInterest();
	Assert.assertEquals(expectedInterest, actualInterest, 0.005);
    }

    @Test
    public void getInterestTest4() {
	SimpleDeposit sd = new SimpleDeposit();
	sd.setStartDate(new GregorianCalendar(2012, Calendar.FEBRUARY, 8)
		.getTime());
	sd.setDayLong(30);
	sd.setSum(1000.00);
	sd.setInterestRate(15.0);
	double expectedInterest = 12.3;
	double actualInterest = sd.getInterest();
	Assert.assertEquals(expectedInterest, actualInterest, 0.005);
    }

    @Test
    public void getInterestTest5() {
	SimpleDeposit sd = new SimpleDeposit();
	sd.setStartDate(new GregorianCalendar(2012, Calendar.MAY, 12).getTime());
	sd.setDayLong(180);
	sd.setSum(1000.00);
	sd.setInterestRate(15.0);
	double expectedInterest = 73.97;
	double actualInterest = sd.getInterest();
	Assert.assertEquals(expectedInterest, actualInterest, 0.005);
    }
}
